/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.MethodVisitor;

import java.util.LinkedList;
import java.util.List;

public class DefaultMethodInstructions implements MethodInstructions {
	private final List<MethodInstruction> instructions = new LinkedList<MethodInstruction>();

	public MethodInstructions add(MethodInstruction instruction) {
		instructions.add(instruction);

		return this;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Instructions Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public void inform() {
		for (MethodInstruction methodInstruction : instructions) {
			inform(methodInstruction);
		}
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public void clear() {
		instructions.clear();
	}

	public void accept(MethodVisitor methodVisitor) {
		for (MethodInstruction instruction : instructions) {
			instruction.accept(methodVisitor);
		}
	}

	public void inform(MethodInstruction methodInstruction) {
		for (MethodInstruction instruction : instructions) {
			instruction.inform(methodInstruction);
		}
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object.getClass().equals(getClass()))) {
			return false;
		}

		DefaultMethodInstructions other = (DefaultMethodInstructions) object;

		return instructions.equals(other.instructions);
	}
}
